<!DOCTYPE html>
<title>WebSocket Test Page</title>
<script>

    var log = function(s) {
        if (document.readyState !== "complete") {
            log.buffer.push(s);
        } else {
            document.getElementById("output").innerText += (s + "\n")
        }
    }
    log.buffer = [];

    url = "ws://localhost:8080/broadcast";
    w = new WebSocket(url);
    w.onopen = function() {
        log("1: open");
        w.send("thank you for accepting this WebSocket request");
    }
    w.onmessage = function(e) {
        log("1:" + e.data);
    }
    w.onclose = function(e) {
        log("1: closed");
    }


    window.onload = function() {
        log(log.buffer.join("\n"))
        document.getElementById("sendButton").onclick = function() {
            w.send(document.getElementById("inputMessage").value);
        }
        document.getElementById("disconnectW2").onclick = function() {
            w2.close();
        }

        url2 = "ws://localhost:8080/broadcast";
        w2 = new WebSocket(url2);
        w2.onopen = function() {
            log("2: open");
        }
        w2.onmessage = function(e) {
            log("2:" + e.data);
        }
        w2.onclose = function(e) {
            log("2: closed");
        }

    }
</script>

<input type="text" id="inputMessage" value="Hello, Web Socket!"><button id="sendButton">Send</button>
<button id="disconnectW2">Disconnect Web Socket 2</button>
<pre id="output"></pre>
